package b6.vacancyshare.activity;

import java.util.Calendar;

import b6.vacancyshare.R;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;

public class MenuPos extends Activity implements AdapterView.OnItemSelectedListener{
	String[] jobtype = {"Full time", "Part time", "Project"};
	EditText duedate;
	Spinner spin;
	Button pickDate;
	Button post;
	int yy, mm, dd;
	static final int DATE_DIALOG_ID = 0;
	
	// the callback received when the user "sets" the date in the dialog
    private DatePickerDialog.OnDateSetListener mDateSetListener =
            new DatePickerDialog.OnDateSetListener() {

                public void onDateSet(DatePicker view, int year, 
                                      int monthOfYear, int dayOfMonth) {
                    yy = year;
                    mm = monthOfYear;
                    dd = dayOfMonth;
                    updateDisplay();
                }
            };
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.form_post);
        
        duedate = (EditText)findViewById(R.id.DueDateTFPost);
        spin = (Spinner)findViewById(R.id.JobTypeSpinnerPost);
        pickDate = (Button)findViewById(R.id.pickDateButtonPost);
        post = (Button)findViewById(R.id.PostButton);
        duedate.setEnabled(false);
        final Intent route1 = new Intent(this, b6.vacancyshare.activity.MenuPencarianPeta.class);
        
        spin.setOnItemSelectedListener(this);
        
        ArrayAdapter<String> aa=new ArrayAdapter<String>(this,
        		android.R.layout.simple_spinner_item,
        		jobtype);
        aa.setDropDownViewResource(
        android.R.layout.simple_spinner_dropdown_item);
        spin.setAdapter(aa);
        
        // get the current date
        final Calendar c = Calendar.getInstance();
        yy = c.get(Calendar.YEAR);
        mm = c.get(Calendar.MONTH);
        dd = c.get(Calendar.DAY_OF_MONTH);
        
        // add a click listener to the button
        pickDate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog(DATE_DIALOG_ID);
            }
        });
        
		post.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				startActivity(route1);
			}
        	
        });
    }
    
    public void onItemSelected(AdapterView<?> parent,
        	View v, int position, long id) {
        }

    public void onNothingSelected(AdapterView<?> arg0) {
    		// TODO Auto-generated method stub
    	}
    
    private void updateDisplay() {
        duedate.setText(
            new StringBuilder()
                    // Month is 0 based so add 1
                    .append(dd).append("/")
                    .append(mm + 1).append("/")
                    .append(yy));
    }
    
    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DATE_DIALOG_ID:
            return new DatePickerDialog(this,
                        mDateSetListener,
                        yy, mm, dd);
        }
        return null;
    }
}